package com.jackie.easyble.ui.activities

import android.Manifest
import android.content.Intent
import android.os.Build
import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.jackie.easyble.R
import com.sscl.baselibrary.activity.BasePermissionCheckActivity

/**
 * 权限请求界面
 */
class PermissionCheckActivity : BasePermissionCheckActivity() {

    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
     *
     * 实现方法
     *
     * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

    override fun needHideNavigationBar(): Boolean {
       return true
    }

    /**
     * 权限请求失败
     */
    override fun permissionRequestFailed() {
        finish()
    }

    /**
     * 有权限被永久拒绝
     * @param failedPermissions 被拒绝的权限
     * @return 是否跳转到系统权限设置界面
     */
    override fun permissionsAlwaysDenied(failedPermissions: Array<String>): Boolean {
        return true
    }

    /**
     * 权限被用户拒绝
     * @param failedPermissions 被拒绝的权限
     * @return 是否继续进行权限请求
     */
    override fun permissionsDenied(failedPermissions: Array<String>): Boolean {
        return true
    }

    /**
     * 需要请求的权限
     */
    override fun permissionsNeedRequest(): Array<String> {
         return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
            arrayOf(
                Manifest.permission.READ_MEDIA_AUDIO,
                Manifest.permission.READ_MEDIA_VIDEO,
                Manifest.permission.READ_MEDIA_IMAGES,
                Manifest.permission.BLUETOOTH_SCAN,
                Manifest.permission.BLUETOOTH_CONNECT,
                Manifest.permission.BLUETOOTH_ADVERTISE,
                Manifest.permission.ACCESS_COARSE_LOCATION,
                Manifest.permission.ACCESS_FINE_LOCATION
            )
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
            arrayOf(
                Manifest.permission.BLUETOOTH_SCAN,
                Manifest.permission.BLUETOOTH_CONNECT,
                Manifest.permission.ACCESS_COARSE_LOCATION,
                Manifest.permission.ACCESS_FINE_LOCATION,
                Manifest.permission.BLUETOOTH_ADVERTISE,
                Manifest.permission.READ_EXTERNAL_STORAGE,
                Manifest.permission.WRITE_EXTERNAL_STORAGE
            )
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            arrayOf(
                Manifest.permission.ACCESS_COARSE_LOCATION,
                Manifest.permission.ACCESS_FINE_LOCATION,
                Manifest.permission.READ_EXTERNAL_STORAGE,
                Manifest.permission.WRITE_EXTERNAL_STORAGE
            )
        } else {
            return arrayOf(
                Manifest.permission.READ_EXTERNAL_STORAGE,
                Manifest.permission.WRITE_EXTERNAL_STORAGE
            )
        }
    }

    /**
     * 权限请求成功
     */
    override fun permissionsRequested() {
        val intent = Intent(this,MainActivity::class.java)
        startActivity(intent)
        finish()
    }

}